/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <string>
#include <cmath>
#include <unordered_map>

using namespace std;

bool
is_prime (int n)
{
  if (n <= 1)
	{
	  return false;
	}
  for (int i = 2; i <= sqrt (n); ++i)
	{
	  if (n % i == 0)
		{
		  return false;
		}
	}
  return true;
}

int
find_closest_prime (int n)
{
  int step = 1;
  while (true)
	{
	  if (is_prime (n + step))
		{
		  return n + step;
		}
	  if (is_prime (n - step))
		{
		  return n - step;
		}
	  step += 1;
	}
}



int
main ()
{
  unordered_map < string, int >word_to_digit = {
	{"zero", 0},
	{"one", 1},
	{"two", 2},
	{"three", 3},
	{"four", 4},
	{"five", 5},
	{"six", 6},
	{"seven", 7},
	{"eight", 8},
	{"nine", 9}
  };



  string input_words;
  getline (cin, input_words);

  string word;
  int number = 0;
  int count = 0;
for (char c:input_words)
	{
	  if (isspace (c))
		{
		 try
		 {
		  number = number * 10 + word_to_digit.at (word); count++;}
		  catch (const out_of_range & oor)
		  {
		  cout << "Wrong input" << endl; return 1;}
		  word = "";}
		  else
		  {
		  word += c;}
		  }

		  try
		  {
		  number = number * 10 + word_to_digit.at (word); count++;}
		  catch (const out_of_range & oor)
		  {
		  cout << "Wrong input" << endl; return 1;}
		  if (count != 3 || number < 100 || number > 999)
		  {
		  cout << "Wrong input" << endl;}
		  else
		  {
		  cout << find_closest_prime (number) << endl;}
		  return 0;}
